package com.lovi.mysql_;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

/**
 * 加载配置文件的方式获取数据源连接
 * 常用！！
 */
public class jdbcConnMytest {
    public static void main(String[] args) throws IOException, SQLException, ClassNotFoundException {
        //读取配置文件信息
        Properties properties = new Properties();
        properties.load(new FileInputStream("src/mysql.properties"));
        String url = (String)properties.get("url");
        String user =  (String)properties.get("user");
        String password =  (String)properties.get("password");
        String driver =  (String)properties.get("driver");
        //反射加载
        Class.forName(driver);
        Connection connection = DriverManager.getConnection(url, user, password);
        System.out.println(connection);
    }
}
